<template>
  <div>
    <el-dialog
      title="删除用户"
      :visible.sync="visible"
      :modal-append-to-body="false"
      :close-on-press-escape="false"
      :close-on-click-modal="false"
      @close="closeDialog"
      
      width="500px"
    >
      <div class="notify">
        <p>
          <strong>注意：</strong>
          <br />标记*的是必须录入数据的字段
        </p>
      </div>
      <el-form :model="form" size="mini">
        <el-form-item label="登录名">
          <el-input readonly v-model="submit.username" placeholder></el-input>
        </el-form-item>
        <el-form-item label="登录名">
          <el-input readonly v-model="submit.name" placeholder></el-input>
        </el-form-item>
        <el-form-item label="*密码">
          <el-input v-model="submit.password" placeholder></el-input>
        </el-form-item>
        <el-form-item label="*确认密码">
          <el-input v-model="check.password2" placeholder></el-input>
        </el-form-item>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button @click="visible = false">取 消</el-button>
        <el-button type="primary" @click="Submit()">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  props: {
    form: {
      style: Object
    }
  },
  data() {
    return {
      submit: {
      },
      check:{
        password2:'',
      },
      visible: true
    };
  },
  methods: {
    Check() {
      if (
        this.submit.password == null ||
        this.submit.password == "" ||
        this.check.password2 == null ||
        this.check.password2 == ""
      ) {
        this.$message.error("请录入必填数据的字段！");
        return false;
      }
      if (this.submit.password != this.check.password2) {
        this.$message.error("两个密码不一致！");
        return false;
      }
      return true;
    },
    Submit() {
      if (this.Check()) {
        this.$http
          .post("/user/updata", {
            username: this.form.username,
            password: this.submit.password
          })
          .then(response => {
            if (response.data == "success") {
              this.$message({
                message: "修改完成",
                type: "success"
              });
              this.NeedRefresh();
              this.visible = false;
            }
          });
      }
    },
    closeDialog() {
      this.$emit("dialog-close");
    },
    NeedRefresh() {
      this.$emit("refresh");
    }
  },
  created() {
    
    this.submit = JSON.parse(JSON.stringify(this.form));
    // window.console.log(this.submit);
    window.console.log(this.check);
    
  }
};
</script>

<style>
</style>